package com.sinosoft.cnmuseum.dao;


import java.util.ArrayList;
import java.util.List;

import org.apache.log4j.Logger;

import com.sinosoft.commontools.record.Record;
import com.sinosoft.dbtools.operate.single.DBSingleTableActorMgr;
import com.sinosoft.cnmuseum.entity.ArchivesBi;


public class ArchivesBiDao extends BaseDao{
	private static Logger logger = Logger.getLogger(ArchivesBiDao.class);

	public ArchivesBiDao() {
		this.actor = DBSingleTableActorMgr.getDBSingleTableActor("archives_bi");
	}
	
	public List<Record> getByIds(List<Object> list){
		List<Record> result = new ArrayList<Record>();
		if(list!=null&&list.size()>0){
			for(Object obj:list){
				try {
					String str = String.valueOf(obj);
					int id = Integer.parseInt(str);
					Record record = this.getById(id);
					if(record!=null)
						result.add(record);
				} catch (Exception e) {
					logger.error(e.toString());
					logger.error("Query ArchivesBi by id:"+obj+", Exception:"+e.getMessage());
				}
			}
		}
		return result;
	}

	public List<Record> getByIntIds(List<Integer> list){
		List<Record> result = new ArrayList<Record>();
		if(list!=null&&list.size()>0){
			for(int id:list){
				try {
					Record record = this.getById(id);
					if(record!=null)
						result.add(record);
				} catch (Exception e) {
					logger.error(e.toString());
					logger.error("Query ArchivesBi by id:"+id+", Exception:"+e.getMessage());
				}
			}
		}
		return result;
	}
	
	public boolean verifyPublicAndArchive(int id){
		try {
			Record record = this.getById(id);
			if(record==null)
				return false;
			int pub = record.getIntValue(ArchivesBi.PUBLICTAG);
			if(pub!=ArchivesBi.PUBLICTAG_YES)
				return false;
			int arc = record.getIntValue(ArchivesBi.ARCHIVETAG);
			if(arc!=ArchivesBi.ARCHIVETAG_YES)
				return false;
		} catch (Exception e) {
			logger.error(e.toString());
			logger.error("Query ArchivesBi by id:"+id+", Exception:"+e.getMessage());
			return false;
		}
		return true;
	}
	

}
